package com.lizheng.yunservice.travel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizheng.yunservice.travel.doamin.VtpCultural;
import com.lizheng.yunservice.travel.doamin.bo.VtpCulturalQueryBoPageSearch;
import com.lizheng.yunservice.travel.doamin.vo.VtpCulturalVoPageSearch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface VtpCulturalMapperPageSearch extends BaseMapper<VtpCultural> {

    @Select("<script>" +
            "SELECT " +
            "  c.cultural_id, " +
            "  c.scenic_id, " +
            "  c.category_id, " +
            "  c.title, " +
            "  c.propaganda, " +
            "  c.summary, " +
            "  c.logo_url, " +
            "  c.video_url, " +
            "  c.creator, " +
            "  c.status, " +
            "  c.likes_num, " +
            "  c.collect_num, " +
            "  c.view_num, " +
            "  DATE_FORMAT(c.create_time, '%Y-%m-%d %H:%i:%s') AS createTime, " +
            "  DATE_FORMAT(c.update_time, '%Y-%m-%d %H:%i:%s') AS updateTime, " +
            "  s.scenic_name, " +
            "  cc.category_name " +
            "FROM vtp_cultural c " +
            "LEFT JOIN vtp_scenic s ON c.scenic_id = s.scenic_id " +
            "LEFT JOIN vtp_cultural_category cc ON c.category_id = cc.category_id " +
            "WHERE c.delete_flag = 0 " +
            "<if test='bo.scenicId != null'>" +
            "  AND c.scenic_id = #{bo.scenicId} " +
            "</if>" +
            "<if test='bo.categoryId != null'>" +
            "  AND c.category_id = #{bo.categoryId} " +
            "</if>" +
            "<if test='bo.title != null and bo.title != \"\"'>" +
            "  AND c.title LIKE CONCAT('%', #{bo.title}, '%') " +
            "</if>" +
            "<if test='bo.status != null'>" +
            "  AND c.status = #{bo.status} " +
            "</if>" +
            "</script>")
    Page<VtpCulturalVoPageSearch> selectAppPage(Page<VtpCulturalVoPageSearch> page, @Param("bo") VtpCulturalQueryBoPageSearch bo);
}
